# 读取person.txt
import os


def read_person_into_dic(path_1):  # 课堂练习
    persons = []
    if not os.path.exists(path_1):
        print("文件不存在")
    else:
        with open(path_1, "r") as f:
            index = 0
            header = []
            for line in f:
                print(line)
                person = line.split(",")
                person[-1] = person[-1].split("\n")[0]

                print(person)
                if index == 0:
                    header = person
                else:
                    dic = dict()
                    dic[header[0]] = person[0]
                    dic[header[1]] = person[1]
                    dic[header[2]] = person[2]
                    persons.append(dic)
                index += 1

    print(persons)


def read_move_date(path_1):
    if not os.path.exists(path_1):
        print("文件不存在")
    else:
        pass


if __name__ == '__main__':
    path_1 = "C:\\Users\\Administrator\\PycharmProjects\\python-teach\\Python教学\\21级34班\\34班实验项目提交文件夹\\data\\persons.txt"
    read_person_into_dic(path_1)
